package com.shitu.soulemo.utils;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.shitu.base.net.model.User;
import com.shitu.base.net.request.RequestHelper;
import com.shitu.base.utils.SP;

public class AccountHelper {
    private static User user = null;
    private static int type = 1; //1是供给方，2是需求方。默认是供给方

    public static void init() {
        String data = SP.get("account");
        if (!TextUtils.isEmpty(data)) {
            user = JSON.parseObject(data, User.class);
            RequestHelper.setToken(user.token);
        }
        type = SP.get("type", 1);
    }

    public static void updateAccount(String data) {
        user = JSON.parseObject(data, User.class);
        RequestHelper.setToken(user.token);
        SP.put("account", data);
    }

    public static User getUser() {
        return user;
    }

    public static void logout() {
        SP.clear("account");
        user = null;
    }

    public static void setType(int type1) {
        type = type1;
        SP.put("type", type1);
    }

    public static int getType() {
        return type;
    }

    public static boolean isRequire() {
        return type == 1;
    }
}
